﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Kay.LazarToDo.Win.AppServices;
using Kay.LazarToDo.Win.Models;

namespace Kay.LazarToDo.Win._Controls
{
    /// <summary>
    /// 项目详情
    /// </summary>
    public partial class ProjectDetails : UserControl
    {
        private readonly ProjectAppService _projectAppService;

        /// <summary>
        /// 项目名称
        /// </summary>
        public string ProjectName
        {
            get => textBoxName.Text;
            set => textBoxName.Text = value;
        }

        /// <summary>
        /// 是否显示
        /// </summary>
        public bool Shown
        {
            get => checkBoxShown.Checked;
            set => checkBoxShown.Checked = value;
        }

        /// <summary>
        /// 详情个数
        /// </summary>
        public int ToDoCount
        {
            get => Convert.ToInt32(linkLabelToDoCount.Text);
            set => linkLabelToDoCount.Text = value.ToString();
        }

        /// <summary>
        /// 项目数据
        /// </summary>
        public TjlProject Project { get; set; }

        /// <summary>
        /// 初始化项目详情
        /// </summary>
        public ProjectDetails()
        {
            InitializeComponent();
            _projectAppService = new ProjectAppService();
        }

        private void buttonSave_Click(object sender, EventArgs e)
        {
            TjlProject entity;
            if (checkBoxDelete.Checked)
            {
                entity = _projectAppService.UpdateOrDeleteProject(Project.Id, true, false);
                if (entity != null)
                {
                    RemoveComplated?.Invoke(this, EventArgs.Empty);
                }
            }
            else
            {
                entity = _projectAppService.UpdateOrDeleteProject(Project.Id, false, true);
                if (entity != null)
                {
                    UpdateComplated?.Invoke(this, EventArgs.Empty);
                }
            }
        }

        /// <summary>
        /// 移除项目成功事件
        /// </summary>
        public event EventHandler RemoveComplated;

        /// <summary>
        /// 修改待办事项成功事件
        /// </summary>
        public event EventHandler UpdateComplated;
    }
}
